package com.joelaws.prototype.server;

import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.joelaws.prototype.client.data.Message;
import com.joelaws.prototype.client.rpc.Messaging;
import com.joelaws.prototype.server.dao.DAOFactory;

public class MessagingImpl extends RemoteServiceServlet implements Messaging {

	private static final long serialVersionUID = 1L;

	public List<Message> getFromMessages(long user) throws Exception {
		System.out.println("getFromMessages start");
		try {
			return DAOFactory.getMessagingDAO().getFromMessages(user);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			System.out.println("getFromMessages end");
		}
	}

	public List<Message> getToMessages(long user) throws Exception {
		System.out.println("getToMessages start");
		try {
			return DAOFactory.getMessagingDAO().getToMessages(user);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			System.out.println("getToMessages end");
		}
	}

	public void storeMessage(Message message) throws Exception {
		System.out.println("storeMessage start");
		try {
			DAOFactory.getMessagingDAO().store(message);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			System.out.println("storeMessage end");
		}

	}

}
